package com.changgou.order.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.order.config.RabbitMQConfig;
import com.changgou.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author kfzhao
 * @version 1.0
 * @className OrderPayListener
 * @description
 * @date 2022/1/4 21:08
 */
@Component
@Slf4j
public class OrderPayListener {
    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = RabbitMQConfig.ORDER_PAY)
    public void receivePayMessage(String message) {
        log.info("接收到了订单支付的消息");
        log.info(message);
        Map map = JSON.parseObject(message, Map.class);
        // 调用业务层，完成订单数据库的修改
        orderService.updatePayStatus((String) map.get("orderId"), (String) map.get("transactionId"));
    }
}
